package main.kotlin.solution

import java.util.*
import kotlin.collections.HashMap
import kotlin.collections.LinkedHashMap

class FirstUniqChar {

    fun firstUniqChar(s: String): Char {
        var list = LinkedList<Char>()
        var notResult = LinkedList<Char>()
        for(c in s){
            if(notResult.contains(c)){
                continue
            }

            if(list.contains(c)){
                list.remove(c)
                notResult.add(c)
            }else{
                list.add(c)
            }

        }
        return list.poll()
    }

    fun firstUniqChar1(s: String): Char {
        var map = LinkedHashMap<Char,Boolean>()

        for(c in s){
            map[c] = !map.contains(c)
        }
        for (entry in map.entries){
            if (entry.value)
                return entry.key
        }
        return ' '
    }

    fun firstUniqChar2(s: String): Char {
        var map = LinkedHashMap<Char,Boolean>()
        map['a'] = true
        map['c'] = true
        map['b'] = true
        map['d'] = true
        map['d'] = true
        for (entry in map.entries){
            println(entry.key)
        }
        return ' '
    }
}